GBML manual / Lists

list_clear

Removes every item from target, leaving it empty (list_length(target) becomes 0). target's own declared capacity is unchanged - it can be filled again afterward.

Syntax

list_clear(target)

Arguments

NameType
targetlist

Returns

Nothing.

Description

Removes every item from target, leaving it empty (list_length(target) becomes 0). target's own declared capacity is unchanged, so it can be filled again afterward.

Useful for a fresh start - clearing a "picked up this room" list when the player enters a new room, say, rather than removing items one at a time.

Example

/// @type {list<int>}
var scores = [10, 20, 30];
list_clear(scores);
var count = list_length(scores); // 0
A real capture - the list and its length before clearing, 3 itemsA real capture - the list and its length before clearing, 3 items
A real capture - the list and its length before clearing, 3 items
The same list after list_clear(scores) - empty, and list_length back to 0The same list after list_clear(scores) - empty, and list_length back to 0
The same list after listclear(scores) - empty, and listlength back to 0

The first capture's own "LENGTH: 3" is not a separate call the example above makes - it is what list_length(scores) would already answer at that point, shown alongside the list so the second capture reads as a real before/after, not just an empty list appearing from nowhere.

On the GBA

The vector's clear() - O(n) in how many items target held (each one's destructor runs), but never touches anything outside target itself.

See also: list_addlist_removelist_lengthlist_filllist_containsData containers